<template>
  <!--  编辑弹窗  -->
  <div class="add-form">

    <el-form ref="dataAddForm" :model="formData" label-position="right" label-width="100px">

      <el-row>
        <el-form-item label="姓名" prop="userName">
          <el-input v-model="formData.userName"/>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item label="手机号">
          <el-input v-model="formData.phone"></el-input>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item label="邮箱">
          <el-input v-model="formData.email"></el-input>
        </el-form-item>
      </el-row>


    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleEdit()">修改</el-button>
    </div>


  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "admin_home",
  data(){
    return{
      formData:{},
    }
  },
  created() {
    this.getInfo();
  },
  methods:{
    getInfo(){
      var id = window.sessionStorage.getItem("token");
      // 发送异步请求
      axios.get("/admin-service/admin-show/" + id).then(res => {
        if (res.data.flag && res.data.data != null) {
          this.formData = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    handleEdit(){
      var id = window.sessionStorage.getItem("token");
      this.formData.id = id;
      axios.put("/admin-service/admin-update", this.formData).then(res => {
            // 判断当前操作是否成功
            if(res.data.flag) {
              this.$message.success(res.data.msg);
              this.getInfo();
            } else {
              this.$message.error(res.data.msg);
            }
          }
      );
    }


  }
}
</script>

<style scoped>

</style>